home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
netsnake
/
frmmain.frm
next >
Wrap
Text File
|
1999-07-27
|
5KB
|
185 lines
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmMain
BorderStyle = 1 'Fixed Single
Caption = "NetSnake"
ClientHeight = 5865
ClientLeft = 3315
ClientTop = 1455
ClientWidth = 10725
Icon = "frmMain.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 5865
ScaleWidth = 10725
Begin VB.Timer timeOut
Enabled = 0 'False
Interval = 60000
Left = 840
Top = 1920
End
Begin MSWinsockLib.Winsock Winout
Left = 4800
Top = 1680
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock Winin
Left = 4440
Top = 1680
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.ListBox lstLog
Height = 5910
Left = 0
TabIndex = 0
Top = 0
Width = 10695
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
On Error GoTo errorHandle
If Command = "" Then End
App.TaskVisible = False
Me.Show
DoEvents
Dim newCom As String
Dim LBuffer As String * 3000
Dim posCount As Long
newCom = Trim(LCase(Command))
lstLog.AddItem newCom
lstLog.AddItem "mode: " & Parse(newCom, 1)
Select Case Parse(newCom, 1)
Case "in"
Winin.LocalPort = CInt(Val(Parse(newCom, 2)))
Winin.Listen
lstLog.AddItem "listening on port " & Winin.LocalPort
timeOut.Enabled = True
Case "out"
Winout.RemoteHost = Parse(newCom, 2)
Winout.RemotePort = CInt(Val(Parse(newCom, 3)))
outFile = Parse(newCom, 4)
inFile = Parse(newCom, 5)
'check file
If Dir(outFile) = "" Then End
'end check file
Winout.Connect
lstLog.AddItem "connecting to " & Winout.RemoteHost & ":" & Winout.RemotePort
lstLog.AddItem "task: send file " & outFile & " -> " & inFile
'wait for connection
timeOut.Enabled = True
Do While Winout.State <> sckConnected: DoEvents: Loop
timeOut.Enabled = False
'start doing stuff
Winout.SendData READY
WaitFor READY
Winout.SendData IN_FILENAME & inFile
WaitFor GOT_FILENAME
Open outFile For Binary As #1
LBuffer = ""
Do While Not EOF(1)
fullCount = fullCount + 1
Get #1, , LBuffer
Winout.SendData IN_DATA & LBuffer
WaitFor RECEIVED
Response = ""
Me.Caption = (fullCount * 3001)
DoEvents
Loop
Close #1
Winout.SendData DONE
lstLog.AddItem "DONE"
timeOut.Enabled = True
Case Else
lstLog.AddItem "INVALID MODE"
End
End Select
Exit Sub
errorHandle:
On Error Resume Next
Open "c:\nslog.log" For Append As #2
Print #2, Err.Number & " - "; Err.Description
Close #2
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub timeOut_Timer()
lstLog.AddItem "TIMEOUT"
End
End Sub
Private Sub Winin_ConnectionRequest(ByVal requestID As Long)
Winin.Close
DoEvents
Winin.Accept requestID
End Sub
Private Sub Winin_DataArrival(ByVal bytesTotal As Long)
timeOut.Enabled = False
Dim cOm As String
Dim writeData As String * 3001
Winin.GetData Response
Data = Right(Response, (Len(Response) - 1))
cOm = Left(Response, 1)
Select Case cOm
Case BUFFER
Case READY
Winin.SendData READY
lstLog.AddItem "SENT READY SIGNAL"
Case IN_FILENAME
inFile = Data
Winin.SendData GOT_FILENAME
lstLog.AddItem "INPUT FILE SET " & inFile
Case IN_DATA
On Error Resume Next
writeData = Data
Open inFile For Binary As #1
Seek #1, LOF(1)
Put #1, , writeData
Close #1
fullCount = fullCount + 1
Me.Caption = (fullCount * 3001): DoEvents 'log bytes received
Winin.SendData RECEIVED
Case DONE
Winin.Close
lstLog.AddItem "DONE"
timeOut.Enabled = True
End Select
Response = ""
timeOut.Enabled = True
End Sub
Private Sub Winout_DataArrival(ByVal bytesTotal As Long)
timeOut.Enabled = False
Winout.GetData Response
timeOut.Enabled = True
End Sub